﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Hangjing.SQLServerDAL;
using Hangjing.Common;
using Hangjing.Model;

/// <summary>
/// 淘宝开放平台信息管理
/// </summary>
public partial class qy_54tss_Admin_activeindexlinklist_taobaoaccount : System.Web.UI.Page
{
    protected string SqlWhere
    {
        get
        {
            return (ViewState["sqlWhere"] == null) ? "" : ViewState["sqlWhere"].ToString();
        }
        set
        {
            ViewState["sqlWhere"] = value;
        }
    }

    taobaoAPIAcount dal = new taobaoAPIAcount();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            getItem();
        }
    }

    protected void getItem()
    {
        AspNetPager1.RecordCount = dal.GetCount(SqlWhere);
        rptsubItem.DataSource = dal.GetList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, SqlWhere, "id", 1);
        rptsubItem.DataBind();
    }


    protected void btSearch_Click(object sender, EventArgs e)
    {
        SqlWhere = "1=1 ";
        if (tbKeyword.Text != "")
        {
            SqlWhere += " and  classname like '%" + WebUtility.InputText(this.tbKeyword.Text) + "%' ";
        }
        getItem();
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "del")
        {
            if (dal.DelList(e.CommandArgument.ToString()) > 0)
            {
                AlertScript.RegScript(this, UpdatePanel1, "jtip('删除成功！');init();");
                getItem();
            }
            else
            {
                AlertScript.RegScript(this, UpdatePanel1, "jtip('删除失败，请重试！');init();");
            }
        }
    }

    protected void GridView_RowEditing(object sender, GridViewEditEventArgs e)
    {
        rptsubItem.EditIndex = e.NewEditIndex;
        getItem();
    }

    protected void GridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        rptsubItem.EditIndex = -1;
        getItem();
    }

    protected void GridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string classname = ((TextBox)rptsubItem.Rows[e.RowIndex].FindControl("Lbl_classname")).Text.Trim();
        string tblinkurl = ((TextBox)rptsubItem.Rows[e.RowIndex].FindControl("tblinkurl")).Text.Trim();
        int id = Convert.ToInt32(((Label)rptsubItem.Rows[e.RowIndex].FindControl("lb_id")).Text.Trim());
        string Lbl_pic = ((TextBox)rptsubItem.Rows[e.RowIndex].FindControl("Lbl_pic")).Text.Trim();
        string Lbl_hovepic = ((TextBox)rptsubItem.Rows[e.RowIndex].FindControl("Lbl_hovepic")).Text.Trim();

        taobaoAPIAcountInfo mm = new taobaoAPIAcountInfo();
        mm.classname = classname;
        mm.hovepic = Lbl_hovepic;
        mm.pic = Lbl_pic;
        mm.Priority = 0;
        mm.ID = id;
        mm.linkurl = tblinkurl;

        if (dal.updateName(mm) > 0)
        {
            AlertScript.RegScript(Page, UpdatePanel1, "jtip('编辑成功！');init();");
            getItem();
        }
        else
        {
            AlertScript.RegScript(Page, UpdatePanel1, "jtip('编辑失败，请重试！');init();");
        }
        rptsubItem.EditIndex = -1;
        getItem();
    }

}

